package cn.stonemind.controller;

import cn.stonemind.domain.Account;
import cn.stonemind.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @PostMapping(value = "/save", produces = {})
    @ResponseBody
    public String save(Account account) {
        this.accountService.save(account);
        return "成功保存";
    }

    @GetMapping("/findAll")
    public ModelAndView findAll() {
        List<Account> accountList = this.accountService.findAll();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("accountList", accountList);
        modelAndView.setViewName("accountList");
        return modelAndView;
    }


}
